home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbuts.zip / DUMP2RAW.C < prev    next >
C/C++ Source or Header  |  1991-05-16  |  4KB  |  186 lines

  1. /**********************************************************
  2.  
  3. DUMP2RAW.C  - Converts a DKB/QRT "Dump" format raw file to
  4.           PICLAB's "raw" format, which is 3 files of
  5.           8-Bit pixel data named .R8, .B8, and .G8.
  6.           On the Amiga, names are .red, .grn, and .blu.
  7.           By Aaron A. Collins, written on 6/30/90
  8.  
  9.           This file is released to the Public Domain.
  10.  
  11.           PICLAB is a trademark of The Stone Soup Group.
  12.               
  13.  ***********************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #ifndef TRUE
  20. #define TRUE 1
  21. #define FALSE 0
  22. #endif
  23.  
  24. #define MAXXRES 2048   /* huge max x resolution allowable, infinite y res. */
  25.  
  26. unsigned char linbuf[MAXXRES * 3];
  27.  
  28. void main(argc,argv)
  29. int argc;
  30. char *argv[];
  31. {
  32.     int xres, yres, xhi, yhi, noext = FALSE;
  33.     register int x, y;
  34.     char inname[80], rname[80], bname[80], gname[80], tmpname[80];
  35.     FILE *in, *rout, *bout, *gout;
  36.  
  37.     printf("\n\nDKB/QRT Image File to Raw R-G-B Files Converter\n");
  38.     printf("By Aaron A. Collins.  Written 6/30/90\n\n");
  39.  
  40.     if (argc < 2)
  41.     {
  42.         printf("Usage: %s InFile[.DIS]\n\n",argv[0]);
  43.         exit(1);
  44.     }
  45.  
  46.     strcpy(inname, argv[1]);      /* get input filename */
  47.  
  48.     strcpy(tmpname, inname);
  49.     strupr(tmpname);        /* Cvt to uppercase */
  50.     if (!strstr(tmpname, ".DIS"))    /* if user didn't supply .DIS ext, */
  51.         if (!strchr(tmpname, '.'))  /* AND didn't supply ANY ext */
  52.         {
  53.             noext = TRUE;
  54.             strcat(inname, ".DIS");
  55.         }
  56.  
  57.     if ((in = fopen(inname, "rb")) == NULL)  /* try w/supplied ext. */
  58.     {
  59.         printf("ERROR - Couldn't open file %s\n", inname);
  60.         exit(1);
  61.     }
  62.  
  63.     if (noext)
  64.     {
  65.         strcpy(rname, argv[1]);        /* copy name w/no extension */
  66.         strcpy(gname, argv[1]);
  67.         strcpy(bname, argv[1]);
  68.     }
  69.     else
  70.     {
  71.         strcpy(tmpname, argv[1]);    /* Get Input Filename */
  72.         strupr(tmpname);        /* Cvt to uppercase */
  73.         *strchr(tmpname, '.') = '\0';    /* Find the Dot + Truncate */
  74.         strcpy(rname, tmpname);        /* copy name w/no extension */
  75.         strcpy(gname, tmpname);
  76.         strcpy(bname, tmpname);
  77.     }
  78.  
  79. #ifdef IBM
  80.     strcat(rname, ".r8");
  81.     strcat(gname, ".g8");
  82.     strcat(bname, ".b8");
  83. #else
  84.     strcat(rname, ".red");
  85.     strcat(gname, ".grn");
  86.     strcat(bname, ".blu");
  87. #endif
  88.     
  89.     if ((rout = fopen(rname, "wb")) == NULL)
  90.     {
  91.         printf("ERROR - Couldn't create file %s\n", rname);
  92.         fclose(in);
  93.         exit(1);
  94.     }
  95.  
  96.     if ((gout = fopen(gname, "wb")) == NULL)
  97.     {
  98.         printf("ERROR - Couldn't create file %s\n", gname);
  99.         fclose(in);
  100.         fclose(rout);
  101.         exit(1);
  102.     }
  103.  
  104.     if ((bout = fopen(bname, "wb")) == NULL)
  105.     {
  106.         printf("ERROR - Couldn't create file %s\n", bname);
  107.         fclose(in);
  108.         fclose(rout);
  109.         fclose(gout);
  110.         exit(1);
  111.     }
  112.  
  113.     /** load x and y resolution from input DUMP file **/
  114.  
  115.     xres = fgetc(in);            /* lo order */
  116.     xhi = fgetc(in);            /* hi order */
  117.     xres += ((unsigned int) xhi) << 8;
  118.     
  119.     if (xres > MAXXRES)            /* too big? */
  120.     {
  121.         printf("ERROR - X res. of %s (%d) exceeds maximum (%d)!\n", inname, xres, MAXXRES);
  122.         fclose(in);            /* close all files */
  123.         fclose(rout);
  124.         fclose(gout);
  125.         fclose(bout);
  126.         unlink(rname);        /* delete empty out files */
  127.         unlink(gname);
  128.         unlink(bname);
  129.         exit(1);
  130.     }
  131.  
  132.     yres = fgetc(in);            /* now do yres the same... */
  133.     yhi = fgetc(in);
  134.     yres += ((unsigned int) yhi) << 8;
  135.  
  136.     printf("Input file         = %s\n", inname);    /* show stats */
  137.     printf("Output files       = %s\n", rname);
  138.     printf("                     %s\n", gname);
  139.     printf("                     %s\n\n", bname);
  140.     printf("Image X resolution = %d\n", xres);
  141.     printf("Image Y resolution = %d\n", yres);
  142.  
  143.     printf("\nProcessing Line:   0");
  144.  
  145.     for (y = 0; y < yres; y++)    /* for every line in the old file */
  146.     {
  147.  
  148.         printf("\b\b\b%3d", y);        /* disp. current line # */
  149.  
  150.         fread(linbuf, 1, 2, in);    /* read in line number */
  151.  
  152.         if (feof(in))            /* stop if file truncated */
  153.             break;
  154.  
  155.         for (x = 0; x < 3; x++)
  156.         {
  157.             fread(linbuf, 1, xres, in); /* read a line's data */
  158.  
  159.             if (feof(in))        /* stop if file truncated */
  160.                 break;
  161.  
  162.             switch (x)
  163.             {
  164.                 case 0:
  165.                     fwrite(linbuf, 1, xres, rout);
  166.                     break;
  167.                 case 1:
  168.                     fwrite(linbuf, 1, xres, gout);
  169.                     break;
  170.                 case 2:
  171.                     fwrite(linbuf, 1, xres, bout);
  172.                     break;
  173.             }
  174.         }
  175.     }
  176.     printf("\n");
  177.     fclose(in);                                 /* close all files */
  178.     fflush(rout);
  179.     fflush(gout);
  180.     fflush(bout);
  181.     fclose(rout);
  182.     fclose(gout);
  183.     fclose(bout);
  184.     exit(0);
  185. }
  186.